
#include	"SysConfig.h"
#include	"Define.h"
#include	"Port.h"
#include	"Function.h"
#include	"Model_Option.h"
#include	"Audio.h"
#ifdef  ST7565P
#include	"ST7565P.h"
#endif
#ifdef  MIC
#include	"MIC.h"
#endif
#ifdef  AUTO_GUIDE
#include	"AutoGuide.h"
#endif
#ifdef  AV_CONTROLLER
#include	"AVController.h"
#endif
#ifdef  HERO
#include	"HERO_Drv.h"
#endif

#ifdef  MIC

MIC_STATUS ucMIC_HostMicStatus;
MIC_STATUS ucMIC_Status;
MIX_MODE ucMIX_Mode;

void MIC_SetHostMicStatus(MIC_STATUS ucMode)
{
	ucMIC_HostMicStatus = ucMode;
}

MIC_STATUS MIC_GetHostMicStatus(void)
{
	return(ucMIC_HostMicStatus);
}

MIC_STATUS MIC_GetMicStatus(void)
{
	return(ucMIC_Status);
}

void MIC_SetMicStatus(MIC_STATUS ucMode)
{
	ucMIC_Status = ucMode;

	if  (ucMIC_Status == MIC_ON)
	{
		HERO_PhoneOnOff(1);
	}
	else
	{
		HERO_PhoneOnOff(0);
	}
}

MIX_MODE MIC_GetMixMode(void)
{
	return(ucMIX_Mode);
}

void MIC_SetMixMode(MIX_MODE ucMode)
{
	ucMIX_Mode = ucMode;

	if  (ucMIX_Mode == MIX_ON)
	{	
		AUDIO_InputSelect(FUNC_GetCurrentFunction());//	
	}
	else
	{
		HERO_PhoneMix(0);
	}
}

void MIC_DISP_MainText(void)
{
	unsigned char ucBuf[15];
	unsigned char ucMicCnt = 0;

	memset(&ucBuf[0], 0x00, sizeof(ucBuf));

	if  (AG_GetMicStatus() == MIC_ON)
	{
		++ucMicCnt;
	}
	if  (AVC_GetMicStatus() != AVC_MIC_OFF)
	{
		++ucMicCnt;
	}
	if  (MIC_GetHostMicStatus() == MIC_ON)
	{
		++ucMicCnt;
	}

	if  (ucMicCnt < 2)
	{
		if  (AG_GetMicStatus() == MIC_ON)
		{
			memcpy(&ucBuf[0], "MIC GUIDE", 9);
		}
		if  (AVC_GetMicStatus() != AVC_MIC_OFF)
		{
			memcpy(&ucBuf[0], "MIC CONT/B", 10);
		}
		if  (MIC_GetHostMicStatus() == MIC_ON)
		{
			memcpy(&ucBuf[0], "MIC HEAD", 8);
		}
	}
	else
	{
		if  ((AG_GetMicStatus() == MIC_ON) && (AVC_GetMicStatus() != AVC_MIC_OFF))
		{
			memcpy(&ucBuf[0], "Mic-G Mic-C", 11);
		}
		if  ((AG_GetMicStatus() == MIC_ON) && (MIC_GetHostMicStatus() == MIC_ON))
		{
			memcpy(&ucBuf[0], "Mic-G Mic-H", 11);
		}
		if  ((AVC_GetMicStatus() != AVC_MIC_OFF) && (MIC_GetHostMicStatus() == MIC_ON))
		{
			memcpy(&ucBuf[0], "Mic-H Mic-C", 11);
		}
	}
#ifdef  ST7565P
	ST7565_UpdateDisplayString(5, &ucBuf[0], 0);
#endif
}

void MIC_DISP_SubText(void)
{
	unsigned char ucBuf[3];
	
	memset(&ucBuf[0], 0x00, sizeof(ucBuf));
	memcpy(&ucBuf[0], "MIC", 3);
#ifdef  ST7565P
	ST7565_UpdateSubDisplayData(&ucBuf[0]);
#endif
}

void MIC_DISP_IconMain(void)
{
//	DISP_IconSetStatusFlag(ICON_MASK_AUX, 0);
}

void UI_TIMER_5msec_Local(unsigned short Times);

void MIC_Main(void)
{
#if  1
	if  (FUNC_GetPowerFlag() == 0)
	{
		return;
	}

	if  (FUNC_PowerStatus() == 0)
	{
		return;
	}

	if  ((MIC_GetHostMicStatus() == MIC_ON) || (AVC_GetMicStatus() > AVC_MIC_OFF) || (AG_GetMicStatus() == MIC_ON))
	{
		if  (MIC_GetMicStatus() == MIC_OFF)
		{
		//	HERO_PhoneOnOff(1);
			HERO_PhoneMix(0);
			MIC_SetMicStatus(MIC_ON);
		}
		
		if  (AVC_GetMicStatus() == AVC_MIX_ON)
		{
			if  (MIC_GetMixMode()== MIX_OFF)
			{
				MIC_SetMixMode(MIX_ON);		
			}
		}
		else
		{
			if  (MIC_GetMixMode()== MIX_ON)
			{
				MIC_SetMixMode(MIX_OFF);
			}
		}
		return;
	}

	if  (MIC_GetMicStatus() == MIC_ON)
	{
	//	MIC_SetMixMode(MIX_OFF);
		MIC_SetMicStatus(MIC_OFF);
	//	FUNC_FunctionChangeStart(FUNC_GetCurrentFunction(),FUNC_CHANGE_SEQ0);
	//	UI_TIMER_5msec_Local(200/5);
		AUDIO_InputSelect(FUNC_GetCurrentFunction());
	//	HERO_SetMute(0);
	}
#endif
}

#endif

